package  com.globagames.strategicgames.business
{
	import com.globagames.strategicgames.model.*;
	
	import mx.rpc.IResponder;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;



	public class CompanyDelegate
	{
		private var service:RemoteObject;
		
		public function CompanyDelegate( responder : IResponder )
		{		
			this.responder = responder;
			service = new RemoteObject();
			service.destination = "companyService";	
				
		}
		public function doCreate( company:Company) : void
		{							
			var call : Object = this.service.createCompany(company);
			call.addResponder( responder );						
		}
		public function doRemove( company:Company) : void
		{							
			var call : Object = this.service.removeCompany(company.companyId);
			call.addResponder( responder );						
		}
		
		public function doFind( company:Company) : void
		{											
			var call : Object = this.service.findCompany(company.companyId);
			call.addResponder( responder );
		}
		public function doAddSoldier( soldier:Soldier, company:Company) : void
		{											
			var call : Object = this.service.addSoldier(soldier, company.companyId);
			call.addResponder( responder );
		}
						
		private function resultHandler(event:ResultEvent):void
		{
			this.responder.result(event);
		}
		
		private function faultHandler(event:FaultEvent):void
		{
			
			this.responder.fault(event);
		}
									
		private var responder : IResponder;

	}

}